package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingGradeDto;
import com.zzyl.entity.NursingGrade;
import com.zzyl.mapper.NursingGradeMapper;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingGradeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Transactional
public class NursingGradeServiceImpl implements NursingGradeService {
    @Autowired
    private NursingGradeMapper nursingGradeMapper;

    /**
     * 查询所有护理等级
     * @return
     */
    @Override
    public List<NursingGradeVo> findAll() {
        return nursingGradeMapper.findAll();
    }

    /**
     * 分页查询护理等级
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingGradeVo> selectPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //1.设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //2.调用mapper方法完成分页查询
        Page<NursingGradeVo> page = nursingGradeMapper.selectPage(name,status);
        //3.返回封装数据
        return PageResponse.of(page, NursingGradeVo.class);
    }

    /**
     *新增护理等级
     * @param nursingGradeDto
     */
    @Override
    public void add(NursingGradeDto nursingGradeDto) {
        NursingGrade nursingGrade = new NursingGrade();
        BeanUtil.copyProperties(nursingGradeDto,nursingGrade);
        nursingGrade.setCreateTime(LocalDateTime.now());
        nursingGrade.setUpdateTime(LocalDateTime.now());
        nursingGradeMapper.insert(nursingGrade);
    }
}
